package hpu.bitenergy.Factory;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import hpu.bitenergy.IFactory.IFactory;

public class Factory {

	/**
	 * 通过此工厂管理子工厂
	 * 01.利用反射
	 * E I L P
	 */
	
	private static final String PROPNAME="src/packageName.properties";
	
	public static IFactory GetIFactory(String type){
		
		try {
//			FileReader reader=new FileReader(PROPNAME);
//			Properties prop = new Properties();  
//            prop.load(reader); 
//			String packName=prop.getProperty(type);
			
			String name=type;
			if(type=="E"){
				name="hpu.bitenergy.Factory.ExpertsFactory";
				}else if(type=="I"){
					name="hpu.bitenergy.Factory.IntelligenceFactory";
				}else if(type=="L"){
					name="hpu.bitenergy.Factory.LiteratureFactory";
				}else{
					name="hpu.bitenergy.Factory.PatentFactroy";
				} 

			
          // return (IFactory) Class.forName(packName).newInstance();
			return (IFactory) Class.forName(name).newInstance();
			 } 
//		catch (FileNotFoundException e) {
//			
//			System.out.println("FileNotFoundException加载配置文件失败");
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			System.out.println("IOException加载配置文件失败");
//		} 
			 catch (InstantiationException e) {
			// TODO Auto-generated catch block
			System.out.println("IFactory实例化失败");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			System.out.println("IFactory实例化失败");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("IFactory实例化失败");
		}
		return null;
	}
	
}
